using UnityEngine;

public class MoveCamera : MonoBehaviour
{
	public Camera camera;

	private bool trackingTouch;

	private Vector3 startTouchPosition;

	private Vector3 cameraStartPosition;

	private Plane ground;

	private void Awake()
	{
		ground = new Plane(Vector3.up, Vector3.zero);
	}

	private Vector3 MouseToGroundPosition(Vector3 position)
	{
		Ray ray = camera.ScreenPointToRay(position);
		float enter = 0f;
		if (ground.Raycast(ray, out enter))
		{
			return ray.GetPoint(enter);
		}
		return Vector3.zero;
	}

	private void Update()
	{
		if (Input.GetMouseButtonDown(0))
		{
			Debug.Log("Tracking touch");
			trackingTouch = true;
			startTouchPosition = MouseToGroundPosition(Input.mousePosition);
			cameraStartPosition = base.transform.position;
		}
		else if (Input.GetMouseButtonUp(0))
		{
			trackingTouch = false;
		}
		if (trackingTouch)
		{
			Vector3 vector = MouseToGroundPosition(Input.mousePosition);
			base.transform.position = cameraStartPosition + (vector - startTouchPosition).OnGround();
		}
	}
}
